// Quotes GRUB

exports.read = function (req, res) {
    console.log('--------Quote read');
    var params = req.body;

    exports.model.Quote.find({}, function (err, rec) {
        res.send({success: true, Quote: rec});
    });
};

exports.add = function (req, res) {
    console.log('--------Quote add');
    var params = req.body;
    var item = new exports.model.Quote(params);

    item.save(function(err) {
        if(err) {
            res.send({success: false, Quote: item});
        }
        else {
            res.send({success: true, Quote: item});
        }
    });
};

exports.update = function (req, res) {
    console.log('--------Quote update');
    var params = req.body;
    var id = params._id;
    console.log('--------Quote update params=',params);
    console.log('--------Quote update id=',id);

    //remove id from values to update
    delete params._id;

    exports.model.Quote.update({"_id": id},{ $set : params}, { upsert: false }, function (err) {
        if(err) {
            res.send({success: false});
        }
        else {
            res.send({success: true});
        }
    });
};

exports.destroy = function (req, res) {
    console.log('--------Quote destroy');
    var params = req.body;

    exports.model.Quote.remove({ "_id": params._id }, function (err) {
        if(err) {
            res.send({success: false});
        }
        else {
            res.send({success: true});
        }
    });
};
